package org.nado.member;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

@Service
@Controller("LoginChkInterceptor")
public class LoginChkInterceptor extends HandlerInterceptorAdapter {
	
	private static final Logger logger = Logger.getLogger("LoginChkInterceptor");

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object hadler) throws Exception {
		
		HttpSession session = request.getSession();
		
				
		logger.info("interceptor........................");

		if (session == null) {
			response.sendRedirect("/web/member/login");
			return false;

		}

		try {
			MemberVO vo = (MemberVO) session.getAttribute("loginInfo");

			if (vo.getMem_id() == null) {
				response.sendRedirect("/web/member/login");
				return false;
			}
		} catch (Exception e) {
			response.sendRedirect("/web/member/login");
		}
		return true;
	}


	@Override
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object hadler, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response,
			Object hadler, ModelAndView mav) throws Exception {
		// TODO Auto-generated method stub

	}

}
